/**
 * 时间 ： 2014-5-27 上午9:41:36
 * 作者 ： HaiTao
 * 描述 ： 当前类的描述信息
 **/
package com.laitaoo.service
{
	import com.laitaoo.event.LoginEvent;
	import com.laitaoo.model.User;
	import com.maclema.mysql.MySqlToken;
	import com.maclema.mysql.ResultSet;
	
	import mx.controls.Alert;
	import mx.rpc.AsyncResponder;

	[RouteEvents]
	[Event(name="loginResult", type="com.laitaoo.event.LoginEvent")]
	[Component]
	public class UserService extends BaseService
	{
		public function UserService()
		{
			super();
		}
		/**
		 * 用户登录 
		 **/
		public function userLogin(user:User):void{
			
			var sql:String = "SELECT * FROM user where userName ='"+user.userName+"' and passWord='"+user.passWord+"'";
			
			var token:MySqlToken = st.executeQuery(sql);
			
			token.addResponder(new AsyncResponder(loginResultHandler,loginFaultHandler,token));
		}
		private function loginResultHandler(data:Object, token:Object):void{
			
			var rs:ResultSet = ResultSet(data);
			
			if(rs.size() == 1){ // 登录成功
				
				var loginEvent:LoginEvent = new LoginEvent(LoginEvent.LOGIN_RESULT);
				dispatchEvent(loginEvent);
			}
		}
		private function loginFaultHandler(info:Object, token:Object):void{
			
			Alert.show("1111");
		}
	}
}